﻿using System;
using System.Buffers;

namespace Communication.Help;

public static class ReadOnlySequenceHelp
{
    public static ushort ToUInt16(this ReadOnlySequence<byte> data)
    {
        return BitConverter.ToUInt16(data.FirstSpan[..2]);
    }

    public static ushort ToUInt16(this ReadOnlyMemory<byte> data)
    {
        return BitConverter.ToUInt16(data.Span[..2]);
    }

    public static int ToInt32(this ReadOnlySequence<byte> data)
    {
        return BitConverter.ToInt32(data.FirstSpan[..4]);
    }
}